package com.todo.member.infrastructure.repository.impl;

import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.utils.StringUtils;
import com.todo.member.common.enums.MemberTaskStatusEnum;
import com.todo.member.infrastructure.entity.condition.MemberTaskCondition;
import com.todo.member.infrastructure.entity.po.MemberTaskPO;
import com.todo.member.infrastructure.mapper.MemberTaskMapper;
import com.todo.member.infrastructure.repository.MemberTaskRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/2/10 11:41
 * @description
 */
@Repository
public class MemberTaskRepositoryImpl implements MemberTaskRepository {

    @Resource
    private MemberTaskMapper memberTaskMapper;

    @Override
    public Boolean insertMemberTaskPO(MemberTaskPO memberTaskPO) {
        if (memberTaskPO == null){
            return false;
        }
        return memberTaskMapper.insertMemberTaskPO(memberTaskPO) > 0;
    }

    @Override
    public Boolean updateMemberTaskPOById(MemberTaskPO memberTaskPO) {
        if (memberTaskPO == null || memberTaskPO.getId() == null){
            return false;
        }
        return memberTaskMapper.updateMemberTaskPOById(memberTaskPO) > 0;
    }

    @Override
    public Boolean removeMemberTaskPOById(Long id) {
        if (id == null || id < 0){
            return false;
        }
        return memberTaskMapper.removeMemberTaskPOById(id);
    }

    @Override
    public MemberTaskPO queryMemberTaskPOById(Long id) {
        if (id == null || id < 0){
            return null;
        }
        return memberTaskMapper.queryMemberTaskPOById(id);
    }

    @Override
    public MemberTaskPO queryMemberTaskPOByTitle(String title) {
        if (StringUtils.isBlank(title)){
            return null;
        }
        return memberTaskMapper.queryMemberTaskPOByTitle(title);
    }

    @Override
    public Boolean updateMemberTaskStatusById(Long id, MemberTaskStatusEnum oldStatus, MemberTaskStatusEnum newStatus) {
        if (id == null || id < 0 || oldStatus == null || newStatus == null){
            return false;
        }
        return memberTaskMapper.updateMemberTaskStatusById(id, oldStatus.getType(), newStatus.getType());
    }

    @Override
    public PageResult<MemberTaskPO> queryMemberTaskPOByPage(MemberTaskCondition memberTaskCondition) {
        return null;
    }
}
